package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.DdCouponAdd;
import com.ktgj.customer.service.IDdCouponAddService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2022-09-28
 */
@RestController
@RequestMapping("/ddCouponAdd")
public class DdCouponAddController extends BaseController
{
    @Autowired
    private IDdCouponAddService ddCouponAddService;

    /**
     * 查询【请填写功能名称】列表
     */
//    @PreAuthorize(hasPermi = "customer:add:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody DdCouponAdd ddCouponAdd)
    {
        startPage();
        List<DdCouponAdd> list = ddCouponAddService.selectDdCouponAddList(ddCouponAdd);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "customer:add:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DdCouponAdd ddCouponAdd) throws IOException
    {
        List<DdCouponAdd> list = ddCouponAddService.selectDdCouponAddList(ddCouponAdd);
        ExcelUtil<DdCouponAdd> util = new ExcelUtil<DdCouponAdd>(DdCouponAdd.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize(hasPermi = "customer:add:query")
    @GetMapping(value = "/{couponAddId}")
    public AjaxResult getInfo(@PathVariable("couponAddId") Long couponAddId)
    {
        return AjaxResult.success(ddCouponAddService.selectDdCouponAddById(couponAddId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "customer:add:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DdCouponAdd ddCouponAdd)
    {
        return toAjax(ddCouponAddService.insertDdCouponAdd(ddCouponAdd));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @PreAuthorize(hasPermi = "customer:add:edit")
//    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody List<DdCouponAdd> ddCouponAdd)
    {
        try
        {
            for (DdCouponAdd tmpObj : ddCouponAdd)
            {
                ddCouponAddService.updateDdCouponAdd(tmpObj);
            }
            return AjaxResult.success("修改成功！");
        } catch (Exception e)
        {
            return AjaxResult.success("修改失败！");
        }
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "customer:add:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{couponAddIds}")
    public AjaxResult remove(@PathVariable Long[] couponAddIds)
    {
        return toAjax(ddCouponAddService.deleteDdCouponAddByIds(couponAddIds));
    }
}
